package lab03.test01;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * Created by lenovo on 2017/11/10.
 */
public class Test {
    public static void main(String[] args){
        //读文件基本操作：读一个文件并打印出来
        //1.字符流来读：1）一次读一行字符;2)一次读一个reader.reader（返回ASCLL码int）完了返回-1
        //2.字节流来读
        String path ="D:\\hello.txt";
        BufferedReader reader = null;
        try {
            reader =new BufferedReader(new FileReader(path));
            String line="";
            while ((line=reader.readLine())!=null){
            //line=reader.readLine();//读取一行
            System.out.println(line);}

           //关闭文件
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
